//#include <Servo.h>
#include <ESP8266WiFi.h>

//Servo di;
//Servo shen;
int DP=90;
int SP=0;
int PV=5;

const char *ssid = "tian";
const char *password = "kmmm0521";
const char *host = "192.168.43.143";
WiFiClient client;
const int tcpPort = 23333;


void setup() {
  // put your setup code here, to run once:
  //di.attach(D5);
  //shen.attach(D6);

  Serial.begin(9600);
  Serial.print("SSID: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(10);
    Serial.println(".x.x.");
  }
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // put your main code here, to run repeatedly:
  while (!client.connected())
  {
    delay(10);
    int a = client.connect(host, tcpPort);
    if(a==0)
    {
      Serial.println("shibai");
    }else 
    {
      Serial.println("chenggong");
      break;
    }
  }

      Serial.println("xxxxxxxxxx");
  while (client.available())//available()表示是否可以获取到数据
  {
    char val = client.read();
    if (val == 'w') { 
      client.print("Get w");
      SP+=PV;
      //shen.write(SP);
    }
    if (val == 's')
    {
      client.print("Get s");
      SP-=PV;
      //shen.write(SP);
    }
    if (val == 'a')
    {
      client.print("Get a");
      DP+=PV;
      //di.write(DP);
    }
    if (val == 'd')
    {
      client.print("Get d");
      DP-=PV;
      //di.write(DP);
    }
  }
}
